package test;

import benchmark.Benchmark;
import data.IntegerDataSetGenerator;
import implementation.sort.AbstractSorter;
import implementation.sort.HeapSort;
import implementation.sort.HeapSortTernary;

import java.util.ArrayList;
import java.util.Comparator;


public class HeapReport {

    private static Benchmark benchmark;
    private static IntegerDataSetGenerator generator;

    public static void main(String[] args) {
        benchmark = new Benchmark();

        HeapSort basic = new HeapSort();
        HeapSortTernary ternary = new HeapSortTernary();
        basic.addSorterListener(benchmark);
        ternary.addSorterListener(benchmark);

        generator = new IntegerDataSetGenerator();
        Comparator comparator = generator.getComparator();
        ArrayList<Integer> nList = getNList();

        for (int i = 0; i < nList.size(); i++) {
            int n = nList.get(i);
            System.out.println("N = " + n);
            ArrayList<Integer> randomList = (ArrayList) generator.createRandom(n);
            
            printReport(basic, comparator, randomList);
            printReport(ternary, comparator, randomList);
        }
    }

    private static void printReport(AbstractSorter sorter, Comparator comparator, ArrayList<Integer> randomList) {
        ArrayList<String> randomListC = (ArrayList) randomList.clone();
        System.out.println("\t" + sorter.getType());

        long t0 = System.currentTimeMillis();
        sorter.sort(comparator, randomListC);
        long tf = System.currentTimeMillis();

        System.out.println("\t\t\tTime: " + (tf - t0));
        System.out.println("\t\t\tComparissons: " + benchmark.getComparisons());
    }

    public static ArrayList<Integer> getNList() {
        ArrayList<Integer> nList = new ArrayList<Integer>();
       /* nList.add(1000);
        nList.add(10000);
        nList.add(100000);
        */nList.add(200000);
        return nList;
    }
}
